package com.oa.lms.apps.actions;

import com.oa.lms.apps.business.user.IUsersService;
import com.oa.lms.apps.constants.IMailStatus;
import com.oa.lms.apps.entity.user.UsersValue;

@SuppressWarnings("serial")
public class LoginAction extends BasicAction {
	
	private IUsersService usersService;
	
	
	private UsersValue userInfo;
	private String userName;
	private String userPwd;

	
	public String login() throws Exception {
		return SUCCESS;
	}
	
	public String logout() throws Exception {
		session.put("login_userInfo", null);
		return SUCCESS;
	}
	
	public String toMain() throws Exception {
		return SUCCESS;
	}
	
	public String loginQueryUsername() throws Exception{
		userInfo = (UsersValue) session.get("login_userInfo");
		response.setContentType("text/html; charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		response.getWriter().write(userInfo.getUserName());
		response.getWriter().close();
		return null;
	}
	
	public String verifyUser() throws Exception{
		String str = "0";
		userInfo = usersService.verifyUser(userName, userPwd);
		if(userInfo != null){
			if(userInfo.getUserInfo().getMailInfo().getStatus() == IMailStatus.INACTIVE)
				str = "1";
			else{
				str = "2";
				session.put("login_userInfo", userInfo);
			}
		}
		response.setHeader("Cache-Control", "no-cache");
		response.getWriter().write(str);
		response.getWriter().close();
		return null;
	}
	
	
	public IUsersService getUsersService() {
		return usersService;
	}

	public void setUsersService(IUsersService usersService) {
		this.usersService = usersService;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserPwd() {
		return userPwd;
	}

	public void setUserPwd(String userPwd) {
		this.userPwd = userPwd;
	}

	
	

}
